package com.beijing.syn;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author Ma Wenqi
 * @Date 2021/3/27 19:00
 * @Version 1.0
 */
//测试JUC安全集合
public class TestJUC {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> copy = new CopyOnWriteArrayList<String>();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {

                copy.add(Thread.currentThread().getName());


            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(copy.size());
    }
}
//输出：10000